package com.learn.converter.entity;

import com.learn.postprocessor.entity.PostProcessorTestEntity;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

/**
 * 自定义转换器
 * @author daify
 * @date 2019-03-30 15:35
 */
public class MyConverter implements Converter<String, PostProcessorTestEntity> {


    @Override
    public PostProcessorTestEntity convert(String s) {
        if(StringUtils.hasLength(s)){
            String[] sources = s.split(",");

            PostProcessorTestEntity entity = new PostProcessorTestEntity();
            entity.setId(Integer.parseInt(sources[0]));
            entity.setName(sources[1]);

            return entity;
        }
        return null;
    }
}
